package com.noexcs.forum.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

/**
 * @author noexcs
 * @since 5/20/2022 6:07 PM
 */
@Data
public class User implements UserDetails {

    int id;

    String username;

    String password;

    private String salt;

    String email;

    /**
     * 0 普通用户 1 超级管理员 2 版主
     */
    int type;

    /**
     * 0 未激活 1已激活
     */
    int status;

    String activationCode;

    String headerUrl;

    Date createTime;

    // 权限列表
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        ArrayList<GrantedAuthority> list = new ArrayList<>();
        list.add((GrantedAuthority) () -> {
            if (type == 1) {
                return "ADMIN";
            }
            return "USER";
        });

        return list;
    }

    // true: 账号未过期
    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    // true：账号未锁定
    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    // true：账号未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    // true：账号已启用
    @Override
    public boolean isEnabled() {
        return false;
    }
}
